﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

/// <summary>
/// Summary description for Housing
/// </summary>
public class Housing
{
    public int id;
    public int applyNoId_HistoryId;
    public string address;
    public float area;
    public string propertyOwner;
    public string ownershipCertificate;
    public string propertyrRight;
    public string remark;
    public bool isComputationAble;

    private string ConnString = SqlHelper.ConnectionString;
    
	public Housing()
	{
	}

    /// <summary>
    /// 获取住房表(原表)数据
    /// </summary>
    /// <param name="applyId"></param>
    /// <returns></returns>
    public DataSet GetHousingById(int Id)
    {
        SqlParameter[] par = new SqlParameter[1];
        par[0] = new SqlParameter("@ID", DbType.Int32);
        par[0].Value = Id;

        DataSet dsGetHousing = SqlHelper.ExecuteDataset(ConnString, CommandType.StoredProcedure,
                                                            "Select_Housing_By_ID", par);

        return dsGetHousing;
    }

    /// <summary>
    /// 获取住房表(历史记录表)数据
    /// </summary>
    /// <param name="applyId"></param>
    /// <returns></returns>
    public DataSet GetHousingHistoryById(int Id)
    {
        SqlParameter[] par = new SqlParameter[1];
        par[0] = new SqlParameter("@ID", DbType.Int32);
        par[0].Value = Id;

        DataSet dsGetHousing = SqlHelper.ExecuteDataset(ConnString, CommandType.StoredProcedure,
                                                            "Select_HousingHistory_By_ID", par);

        return dsGetHousing;
    }

    /// <summary>
    /// 添加住房表（原表）
    /// </summary>
    /// <param name="housing"></param>
    /// <returns></returns>
    public bool Addhousing(Housing housing)
    {
        SqlParameter[] par = new SqlParameter[7];
        par[0] = new SqlParameter("@ApplyNoID", DbType.Int32);
        par[0].Value = housing.applyNoId_HistoryId;
        par[1] = new SqlParameter("@Address", DbType.String);
        par[1].Value = housing.address;
        par[2] = new SqlParameter("@Area", DbType.Double);
        par[2].Value = housing.area;
        par[3] = new SqlParameter("@PropertyOwner", DbType.String);
        par[3].Value = housing.propertyOwner;
        par[4] = new SqlParameter("@OwnershipCertificate", DbType.String;
        par[4].Value = housing.ownershipCertificate;
        par[5] = new SqlParameter("@PropertyrRight", DbType.String);
        par[5].Value = housing.propertyrRight;
        par[6] = new SqlParameter("@Remark", DbType.String);
        par[6].Value = housing.remark;
        par[6] = new SqlParameter("@IsComputationAble", DbType.Boolean);
        par[6].Value = housing.IsComputationAble;

        bool addsucc = Convert.ToBoolean(SqlHelper.ExecuteNonQuery(ConnString, CommandType.StoredProcedure,
                                                                    "Insert_Housing", par));

        return addsucc;
    }

    /// <summary>
    /// 添加住房表（历史记录表）
    /// </summary>
    /// <param name="housing"></param>
    /// <returns></returns>
    public bool AddHousingHistory(Housing housing)
    {
        SqlParameter[] par = new SqlParameter[7];
        par[0] = new SqlParameter("@ApplyHistoryID", DbType.Int32);
        par[0].Value = housing.applyNoId_HistoryId;
        par[1] = new SqlParameter("@Address", DbType.String);
        par[1].Value = housing.address;
        par[2] = new SqlParameter("@Area", DbType.Double);
        par[2].Value = housing.area;
        par[3] = new SqlParameter("@PropertyOwner", DbType.String);
        par[3].Value = housing.propertyOwner;
        par[4] = new SqlParameter("@OwnershipCertificate", DbType.String;
        par[4].Value = housing.ownershipCertificate;
        par[5] = new SqlParameter("@PropertyrRight", DbType.String);
        par[5].Value = housing.propertyrRight;
        par[6] = new SqlParameter("@Remark", DbType.String);
        par[6].Value = housing.remark;
        par[6] = new SqlParameter("@IsComputationAble", DbType.Boolean);
        par[6].Value = housing.IsComputationAble;

        bool addsucc = Convert.ToBoolean(SqlHelper.ExecuteNonQuery(ConnString, CommandType.StoredProcedure,
                                                                    "Insert_HousingHistory", par));

        return addsucc;
    }

    /// <summary>
    /// 删除住房表（原表）
    /// </summary>
    /// <param name="Id"></param>
    /// <returns></returns>
    public bool DeleteHousingById(int Id)
    {
        SqlParameter[] par = new SqlParameter[1];
        par[0] = new SqlParameter("@ID", DbType.Int32);
        par[0].Value = Id;

        bool deletesucc = Convert.ToBoolean(SqlHelper.ExecuteNonQuery(ConnString,
                                                                      CommandType.StoredProcedure,
                                                                      "Delete_Housing_By_Id", par));
        return deletesucc;
    }

    /// <summary>
    /// 删除住房表（历史记录表）
    /// </summary>
    /// <param name="Id"></param>
    /// <returns></returns>
    public bool DeleteHousingHistoryById(int Id)
    {
        SqlParameter[] par = new SqlParameter[1];
        par[0] = new SqlParameter("@ID", DbType.Int32);
        par[0].Value = Id;

        bool deletesucc = Convert.ToBoolean(SqlHelper.ExecuteNonQuery(ConnString,
                                                                      CommandType.StoredProcedure,
                                                                      "Delete_HousingHistory_By_Id", par));

        return deletesucc;
    }

    public bool Updatehousing()
    {
        return true;
    }

    public bool UpdatehousingHistory()
    {
        return true;
    }
}
